/**********************************************************************
 Copyright (C) 2009 Jaakko Vuori

 This file is part of FlexiWorker.
 For more information, see <http://code.google.com/p/flexi-worker/>

 FlexiWorker is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 FlexiWorker is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with FlexiWorker.  If not, see <http://www.gnu.org/licenses/>.
 **********************************************************************/

#ifndef TIMELINEWIDGET_H
#define TIMELINEWIDGET_H

#include <QWidget>
#include <QDateTime>

#include "presencelogmodel.h"
#include "resizefsm_sm.h"

class TimeLineWidget : public QWidget
{
    Q_OBJECT
public:
    TimeLineWidget(QWidget* parent = NULL);

    void setDayStartTime(QDateTime dayStartTime);
    QDateTime dayStartTime() const;

    void setPresenceTimes(QList<TimeFrame> presenceTimes);
    void setWorkingTimes(QList<TimeFrame> workingTimes);

    int highlightedWorkingTime() const;

    void savePos();
    void restorePos();
    void handleNewPos();

signals:
    void workingTimeAdjusted(TimeLineWidget* timeLineWidget, TimeFrame workingTime);

protected:
    void paintEvent(QPaintEvent* event);
    void mouseMoveEvent(QMouseEvent* event);
    void mousePressEvent(QMouseEvent* event);
    void mouseReleaseEvent(QMouseEvent* event);
    void leaveEvent(QEvent* event);

private:
    qreal timeToPos(const QDateTime& time);
    QDateTime posToTime(qreal position);

private:
    QFont m_font;
    qreal m_fontHeight;
    qreal m_zeroWidth;
    QDateTime m_dayStartTime;
    QList<TimeFrame> m_presenceTimes;
    QList<TimeFrame> m_workTimes;
    qreal m_startDragPos;
    enum WorkTimeEnd {Beginning, End} m_workTimeEnd;
    TimeLineWidgetContext m_resizeFSM;
    //int m_resizingStartEventIndex;
    //int m_resizingEndEventIndex;
    //bool m_resizing;
    int m_highlightedWorkingTime;
    int m_highlightedPresenceTime;
};

#endif // TIMELINEWIDGET_H
